package com.transitionseverywhere;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.graphics.Color;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import com.transitionseverywhere.Transition;
import java.util.Map;

/* loaded from: classes.dex */
public class ChangeText extends Transition {
    public static final int CHANGE_BEHAVIOR_IN = 2;
    public static final int CHANGE_BEHAVIOR_KEEP = 0;
    public static final int CHANGE_BEHAVIOR_OUT = 1;
    public static final int CHANGE_BEHAVIOR_OUT_IN = 3;
    private static final String LOG_TAG = "TextChange";
    private static final String PROPNAME_TEXT_COLOR = "android:textchange:textColor";
    private int mChangeBehavior = 0;
    private static final String PROPNAME_TEXT = "android:textchange:text";
    private static final String PROPNAME_TEXT_SELECTION_START = "android:textchange:textSelectionStart";
    private static final String PROPNAME_TEXT_SELECTION_END = "android:textchange:textSelectionEnd";
    private static final String[] sTransitionProperties = {PROPNAME_TEXT, PROPNAME_TEXT_SELECTION_START, PROPNAME_TEXT_SELECTION_END};

    public ChangeText setChangeBehavior(int i) {
        if (i >= 0 && i <= 3) {
            this.mChangeBehavior = i;
        }
        return this;
    }

    @Override // com.transitionseverywhere.Transition
    public String[] getTransitionProperties() {
        return sTransitionProperties;
    }

    public int getChangeBehavior() {
        return this.mChangeBehavior;
    }

    private void captureValues(TransitionValues transitionValues) {
        if (transitionValues.view instanceof TextView) {
            TextView textView = (TextView) transitionValues.view;
            transitionValues.values.put(PROPNAME_TEXT, textView.getText());
            if (textView instanceof EditText) {
                transitionValues.values.put(PROPNAME_TEXT_SELECTION_START, Integer.valueOf(textView.getSelectionStart()));
                transitionValues.values.put(PROPNAME_TEXT_SELECTION_END, Integer.valueOf(textView.getSelectionEnd()));
            }
            if (this.mChangeBehavior > 0) {
                transitionValues.values.put(PROPNAME_TEXT_COLOR, Integer.valueOf(textView.getCurrentTextColor()));
            }
        }
    }

    @Override // com.transitionseverywhere.Transition
    public void captureStartValues(TransitionValues transitionValues) {
        captureValues(transitionValues);
    }

    @Override // com.transitionseverywhere.Transition
    public void captureEndValues(TransitionValues transitionValues) {
        captureValues(transitionValues);
    }

    @Override // com.transitionseverywhere.Transition
    public Animator createAnimator(ViewGroup viewGroup, TransitionValues transitionValues, TransitionValues transitionValues2) {
        int i;
        int i2;
        int i3;
        int i4;
        int i5;
        int i6;
        int i7;
        char c;
        final int i8;
        ValueAnimator valueAnimator;
        ValueAnimator ofInt;
        final int i9;
        final int i10;
        AnimatorSet animatorSet;
        if (transitionValues == null || transitionValues2 == null || !(transitionValues.view instanceof TextView) || !(transitionValues2.view instanceof TextView)) {
            return null;
        }
        final TextView textView = (TextView) transitionValues2.view;
        Map<String, Object> map = transitionValues.values;
        Map<String, Object> map2 = transitionValues2.values;
        String str = map.get(PROPNAME_TEXT) != null ? (CharSequence) map.get(PROPNAME_TEXT) : "";
        String str2 = map2.get(PROPNAME_TEXT) != null ? (CharSequence) map2.get(PROPNAME_TEXT) : "";
        boolean z = textView instanceof EditText;
        if (z) {
            int intValue = map.get(PROPNAME_TEXT_SELECTION_START) != null ? ((Integer) map.get(PROPNAME_TEXT_SELECTION_START)).intValue() : -1;
            int intValue2 = map.get(PROPNAME_TEXT_SELECTION_END) != null ? ((Integer) map.get(PROPNAME_TEXT_SELECTION_END)).intValue() : intValue;
            int intValue3 = map2.get(PROPNAME_TEXT_SELECTION_START) != null ? ((Integer) map2.get(PROPNAME_TEXT_SELECTION_START)).intValue() : -1;
            i3 = intValue3;
            i4 = map2.get(PROPNAME_TEXT_SELECTION_END) != null ? ((Integer) map2.get(PROPNAME_TEXT_SELECTION_END)).intValue() : intValue3;
            i = intValue;
            i2 = intValue2;
        } else {
            i = -1;
            i2 = -1;
            i3 = -1;
            i4 = -1;
        }
        if (str.equals(str2)) {
            return null;
        }
        if (this.mChangeBehavior != 2) {
            textView.setText(str);
            if (z) {
                setSelection((EditText) textView, i, i2);
            }
        }
        if (this.mChangeBehavior == 0) {
            valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
            final CharSequence charSequence = str;
            final CharSequence charSequence2 = str2;
            final int i11 = i3;
            final int i12 = i4;
            valueAnimator.addListener(new AnimatorListenerAdapter() { // from class: com.transitionseverywhere.ChangeText.1
                @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
                public void onAnimationEnd(Animator animator) {
                    if (charSequence.equals(textView.getText())) {
                        textView.setText(charSequence2);
                        TextView textView2 = textView;
                        if (textView2 instanceof EditText) {
                            ChangeText.this.setSelection((EditText) textView2, i11, i12);
                        }
                    }
                }
            });
            i6 = i;
            i5 = i2;
            i10 = 0;
        } else {
            final int intValue4 = ((Integer) map.get(PROPNAME_TEXT_COLOR)).intValue();
            int intValue5 = ((Integer) map2.get(PROPNAME_TEXT_COLOR)).intValue();
            int i13 = this.mChangeBehavior;
            if (i13 == 3 || i13 == 1) {
                ValueAnimator ofInt2 = ValueAnimator.ofInt(255, 0);
                ofInt2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // from class: com.transitionseverywhere.ChangeText.2
                    @Override // android.animation.ValueAnimator.AnimatorUpdateListener
                    public void onAnimationUpdate(ValueAnimator valueAnimator2) {
                        int intValue6 = ((Integer) valueAnimator2.getAnimatedValue()).intValue();
                        TextView textView2 = textView;
                        int i14 = intValue4;
                        textView2.setTextColor((intValue6 << 24) | (16711680 & i14) | (65280 & i14) | (i14 & 255));
                    }
                });
                final CharSequence charSequence3 = str;
                i5 = i2;
                i6 = i;
                i7 = 3;
                final CharSequence charSequence4 = str2;
                c = 1;
                final int i14 = i3;
                i8 = intValue5;
                final int i15 = i4;
                ofInt2.addListener(new AnimatorListenerAdapter() { // from class: com.transitionseverywhere.ChangeText.3
                    @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
                    public void onAnimationEnd(Animator animator) {
                        if (charSequence3.equals(textView.getText())) {
                            textView.setText(charSequence4);
                            TextView textView2 = textView;
                            if (textView2 instanceof EditText) {
                                ChangeText.this.setSelection((EditText) textView2, i14, i15);
                            }
                        }
                        textView.setTextColor(i8);
                    }
                });
                valueAnimator = ofInt2;
            } else {
                i8 = intValue5;
                i6 = i;
                i5 = i2;
                valueAnimator = null;
                i7 = 3;
                c = 1;
            }
            int i16 = this.mChangeBehavior;
            if (i16 == i7 || i16 == 2) {
                ofInt = ValueAnimator.ofInt(0, 255);
                i9 = i8;
                ofInt.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // from class: com.transitionseverywhere.ChangeText.4
                    @Override // android.animation.ValueAnimator.AnimatorUpdateListener
                    public void onAnimationUpdate(ValueAnimator valueAnimator2) {
                        textView.setTextColor((((Integer) valueAnimator2.getAnimatedValue()).intValue() << 24) | (Color.red(i9) << 16) | (Color.green(i9) << 8) | Color.red(i9));
                    }
                });
                ofInt.addListener(new AnimatorListenerAdapter() { // from class: com.transitionseverywhere.ChangeText.5
                    @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
                    public void onAnimationCancel(Animator animator) {
                        textView.setTextColor(i9);
                    }
                });
            } else {
                i9 = i8;
                ofInt = null;
            }
            if (valueAnimator != null && ofInt != null) {
                AnimatorSet animatorSet2 = new AnimatorSet();
                Animator[] animatorArr = new Animator[2];
                animatorArr[0] = valueAnimator;
                animatorArr[c] = ofInt;
                animatorSet2.playSequentially(animatorArr);
                animatorSet = animatorSet2;
                i10 = i9;
            } else if (valueAnimator != null) {
                i10 = i9;
            } else {
                i10 = i9;
                animatorSet = ofInt;
            }
            final CharSequence charSequence5 = str2;
            final int i17 = i3;
            final int i18 = i4;
            final CharSequence charSequence6 = str;
            final int i19 = i6;
            final int i20 = i5;
            addListener(new Transition.TransitionListenerAdapter() { // from class: com.transitionseverywhere.ChangeText.6
                int mPausedColor = 0;

                @Override // com.transitionseverywhere.Transition.TransitionListenerAdapter, com.transitionseverywhere.Transition.TransitionListener
                public void onTransitionPause(Transition transition) {
                    if (ChangeText.this.mChangeBehavior != 2) {
                        textView.setText(charSequence5);
                        TextView textView2 = textView;
                        if (textView2 instanceof EditText) {
                            ChangeText.this.setSelection((EditText) textView2, i17, i18);
                        }
                    }
                    if (ChangeText.this.mChangeBehavior > 0) {
                        this.mPausedColor = textView.getCurrentTextColor();
                        textView.setTextColor(i10);
                    }
                }

                @Override // com.transitionseverywhere.Transition.TransitionListenerAdapter, com.transitionseverywhere.Transition.TransitionListener
                public void onTransitionResume(Transition transition) {
                    if (ChangeText.this.mChangeBehavior != 2) {
                        textView.setText(charSequence6);
                        TextView textView2 = textView;
                        if (textView2 instanceof EditText) {
                            ChangeText.this.setSelection((EditText) textView2, i19, i20);
                        }
                    }
                    if (ChangeText.this.mChangeBehavior > 0) {
                        textView.setTextColor(this.mPausedColor);
                    }
                }
            });
            return animatorSet;
        }
        animatorSet = valueAnimator;
        final CharSequence charSequence52 = str2;
        final int i172 = i3;
        final int i182 = i4;
        final CharSequence charSequence62 = str;
        final int i192 = i6;
        final int i202 = i5;
        addListener(new Transition.TransitionListenerAdapter() { // from class: com.transitionseverywhere.ChangeText.6
            int mPausedColor = 0;

            @Override // com.transitionseverywhere.Transition.TransitionListenerAdapter, com.transitionseverywhere.Transition.TransitionListener
            public void onTransitionPause(Transition transition) {
                if (ChangeText.this.mChangeBehavior != 2) {
                    textView.setText(charSequence52);
                    TextView textView2 = textView;
                    if (textView2 instanceof EditText) {
                        ChangeText.this.setSelection((EditText) textView2, i172, i182);
                    }
                }
                if (ChangeText.this.mChangeBehavior > 0) {
                    this.mPausedColor = textView.getCurrentTextColor();
                    textView.setTextColor(i10);
                }
            }

            @Override // com.transitionseverywhere.Transition.TransitionListenerAdapter, com.transitionseverywhere.Transition.TransitionListener
            public void onTransitionResume(Transition transition) {
                if (ChangeText.this.mChangeBehavior != 2) {
                    textView.setText(charSequence62);
                    TextView textView2 = textView;
                    if (textView2 instanceof EditText) {
                        ChangeText.this.setSelection((EditText) textView2, i192, i202);
                    }
                }
                if (ChangeText.this.mChangeBehavior > 0) {
                    textView.setTextColor(this.mPausedColor);
                }
            }
        });
        return animatorSet;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void setSelection(EditText editText, int i, int i2) {
        if (i < 0 || i2 < 0) {
            return;
        }
        editText.setSelection(i, i2);
    }
}
